package forestsimulatorp3.model.position;

/**
 * Represents a position that every living being occupies in the forest.
 * @author dielson
 */
public class Square {

    // Attributes --------------------------------------------------------------
    private int x;
    private int y;

    // Constructors ------------------------------------------------------------
    protected Square(int x, int y) {
        this.x = x;
        this.y = y;
    }

    // Getters & setters -------------------------------------------------------
    public int getX() {
        return x;
    }

    public void setX(int x) {
        if (x < 0) {
            x = Math.abs(x);
        }
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        if (y < 0) {
            y = Math.abs(y);
        }
        this.y = y;
    }

    // Overrides Object --------------------------------------------------------

    @Override
    public boolean equals(Object obj) {
        if (obj instanceof Square) {
            Square p = (Square) obj;
            return ((this.getX() == p.getX()) &&
                    (this.getY() == p.getY()));
        }
        return false;
    }

    @Override
    public int hashCode() {
        int hash = 1;
        hash = 47 * hash + this.getX();
        hash = 47 * hash + 3 * this.getY();
        return hash;
    }

    @Override
    public String toString() {
        return "(" + x + ", " + y + ")";
    }
}
